"""
1.学习目标
    掌握script脚本写法
2.操作步骤
    - 1.封装业务层
    - 2.调用page类中操作方法
3.需求
    对ECShop登录页面进行script封装
4. 总结
    
"""
from page.register_page import RegisterPage
from common.base import open_browser
from page.register_page import register_url
from common.register_data1 import RegisterData
from common.exceluntil import ExcelUntil




class RegisterScript:
    def __init__(self,driver):
        """导入浏览器和实例化page类"""
        self.register_page = RegisterPage(driver)
        self.register_page.open_url(register_url)


    def register_all(self,data):
        """
        注册全部填写登录
        :param username:
        :param password:
        :return:
        """
        self.register_page.input_username(data["username"])
        self.register_page.input_email(data["email"])
        self.register_page.input_password(data["password"])
        self.register_page.input_affirm_password(data["cf_password"])
        self.register_page.input_tel(data["tel"])
        self.register_page.slect_password_hint()
        self.register_page.input_password3(data["answer"])
        self.register_page.click_login()

    def register_required(self,data):
        '''注册必填选项'''
        self.register_page.input_username(data["username"])
        self.register_page.input_email(data["email"])
        self.register_page.input_password(data["password"])
        self.register_page.input_affirm_password(data["password"])
        self.register_page.input_tel(data["tel"])
        self.register_page.click_login()
    def click_look_text(self):
       self.register_page.click_look()
        #我已经看过
    def click_password(self):
        self.register_page.click_log_in()
        #已经有账户
    def clikc_password4(self):
        self.register_page.clik_forget_password()
                #忘记密码





    def is_login_success(self,username):
        """判断是否登陆成功"""
        login_success_loc = ("class name","f4_b")
        result = self.register_page.is_text_in_element(login_success_loc,username)
        return result
if __name__ == '__main__':
    driver = open_browser()
    # register = RegisterPage(driver)
    # register.open_url(register_url)
    register_script = RegisterScript(driver)
    data = RegisterData()
    book = ExcelUntil("../data/test.xls")
    # username = "诸葛亮"
    # password = "Test123456"
    # email='1140945843@qq.com'
    # tel='41414'
    # passwordA="Test123456"
    # password3="嘻嘻"
    register_data = data.all_data()
    register_list = data.data_values_for_list(register_data)
    book.write_data(register_list)

    # register_script.register_all(username,password,email,tel,passwordA,password3)
    # register_script.register_all(username,email,password,tel,password3)

    register_script.register_all(register_data)
